import { EventKeyboard, EventMouse, Game, KeyCode, director, game } from "cc";
import { Input } from "cc";

// import BaseInputMgr from "../../sdk/base/BaseInputMgr";
// import GameInputMgr from "../input/GameInputMgr";
// import { InputType } from "../input/InputConfig";
import { CC_KEY_CODE } from "./CocosDefine";
import CocosGlobalInput from "./CocosGlobalInput";
import BaseInputMgr from "../core/BaseInputMgr";
import { InputType } from "../core/InputConfig";
/**
 * 按键对应的值
 */
// let CC_MOUSE_CODE = {

// }
// let BTN_MAP: number[] = [CC_KEY_CODE.MOUSE_LEFT, 0, CC_KEY_CODE.MOUSE_RIGHT]

// @siclass('CocosInputMgr')
export default class CocosInputMgr extends BaseInputMgr {
    protected platName: string = InputType.CC;
    protected input: CocosGlobalInput = CocosGlobalInput.getInstance();
    protected keyState: { [key: number]: boolean } = {}
    constructor() {
        super();
        this.addKeyCode(CC_KEY_CODE)
        this.init()
    }

    init() {
        this.input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
        this.input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
        this.input.on(Input.EventType.KEY_PRESSING, this.onKeyPressing, this)
        this.input.on(Input.EventType.MOUSE_DOWN, this.onMouseDown, this);
        this.input.on(Input.EventType.MOUSE_UP, this.onMouseUp, this);
        this.input.on(Input.EventType.MOUSE_MOVE, this.onMouseMove, this);
    }

    clear() {
        this.input.off(Input.EventType.KEY_DOWN, this.onKeyDown, this);
        this.input.off(Input.EventType.KEY_UP, this.onKeyUp, this);
        this.input.off(Input.EventType.KEY_PRESSING, this.onKeyPressing, this)
        this.input.off(Input.EventType.MOUSE_DOWN, this.onMouseDown, this);
        this.input.off(Input.EventType.MOUSE_UP, this.onMouseUp, this);
        this.input.off(Input.EventType.MOUSE_MOVE, this.onMouseMove, this);
    }

    //TODOcgw 按住状态
    protected onKeyPressing(event: EventKeyboard) {

    }

    protected onKeyDown(event: EventKeyboard) {
        // console.warn(' onKeyDown ', event.keyCode)
        if (this.keyState[event.keyCode]) {
            return;
        }
        this.keyState[event.keyCode] = true;
        this.changeType()
        this.onKeyBoardPress(event.keyCode)
    }


    protected onKeyUp(event: EventKeyboard) {
        // console.warn(' onKeyUp ', event.keyCode)
        this.keyState[event.keyCode] = false;
        this.onKeyBoardRelease(event.keyCode)
    }

    protected onMouseDown(event: EventMouse) {
        // console.warn(' onMouseDown ', event.getButton())
        this.changeType()

    }

    protected onMouseUp(event: EventMouse) {
    }

    protected onMouseMove(event: EventMouse) {

    }
}

